<template>
  <a-modal
    v-model:visible="show"
    title="工单签名"
    width="400px"
    height="600px"
    class="dispatchContainer"
    :confirm-loading="confirmLoading"
    @ok="ok"
  >
    <div ref="content" class="w-full">
      <Sign :height="300" :value="url" />
    </div>
  </a-modal>
</template>
<script lang="ts" setup>
import { useI18n } from "/@/locales/useI18n";
import { nextTick, ref, watch } from "vue";
import { FormAddItem } from "/@/api/aiot/message/models";
import { signIn } from "/@/api/aiot/serviceWorkOrder";
import { message } from "ant-design-vue";
import { SignInWorkOrder } from "/@/api/aiot/serviceWorkOrder/models";
import { useOrderModal } from "./useOrderModal";

const { t } = useI18n();
const url = ref<string>();
const props = defineProps<{
  workOrderId?: string;
  visible: boolean;
}>();
const emits = defineEmits(["create", "update:visible"]);
const { signinIns, locDgVisible, chooseLoc, signinModelFormSetting, signinModel } = useOrderModal();
const show = ref<boolean>(false);
watch(
  () => props.visible,
  (v) => {
    show.value = v;
    if (!v) {
      reset();
    }
  }
);
let firstShow = true;
watch(show, (v) => {
  emits("update:visible", v);
  if (v) {
    nextTick(() => {
      signinIns.value?.initFormItemComponentData();
    });
  }
  if (firstShow) {
    firstShow = false;
  }
});
//窗口关闭
function cancel() {
  emits("update:visible", false);
  reset();
}
//
function reset() {
  if (signinIns.value) {
    signinIns.value.resetFields();
  }
}
const content = ref<HTMLDivElement>();
const confirmLoading = ref<boolean>(false);
function ok() {
  if (!signinIns.value) return;
  signinIns.value
    .validate()
    .then(async (data: FormAddItem) => {})
    .catch(() => {
      if (content.value) {
        (content.value.parentNode as HTMLDivElement).scrollTop = 0;
      }
    });
}
</script>
